package com.woniuxy.common.utils;

import lombok.*;

/**
 * 统一响应工具类（供所有服务使用）
 */
@Getter
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class ResponseUtil {
    private Integer code; // 0-成功，1-失败
    private String msg;
    private Object data;

    public ResponseUtil(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static ResponseUtil get(ResponseEnum responseEnum, Object object) {
        return new ResponseUtil(responseEnum.getCode(), responseEnum.getMsg(), object);
    }

    //不带参数的返回
    public static ResponseUtil get(ResponseEnum responseEnum) {
        return new ResponseUtil(responseEnum.getCode(), responseEnum.getMsg());
    }

    // 成功响应（带数据）
    public static ResponseUtil success(Object data) {
        ResponseUtil response = new ResponseUtil();
        response.setCode(0);
        response.setMsg("成功");
        response.setData(data);
        return response;
    }

    // 成功响应（不带数据）
    public static ResponseUtil success(String msg) {
        ResponseUtil response = new ResponseUtil();
        response.setCode(0);
        response.setMsg(msg);
        return response;
    }

    // 失败响应
    public static ResponseUtil error(String msg) {
        ResponseUtil response = new ResponseUtil();
        response.setCode(1);
        response.setMsg(msg);
        return response;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setData(Object data) {
        this.data = data;
    }
}